package com.huajx.jrb.service;

import com.huajx.core.common.Columns;
import com.huajx.jrb.model.Borrow;
import com.huajx.util.ObjectUtil;

import java.util.List;

public class BorrowService extends BaseService<Borrow> {

    public static final BorrowService service = new BorrowService(Borrow.class);

    private BorrowService(Class<Borrow> modelClass) {
        super(modelClass);
    }

    public Borrow findLastedByArchiveId(Long archiveId){
        Columns columns = Columns.create();
        columns.eq("archiveId", archiveId);
        columns.eq("status", "借出");
        List<Borrow> borrows = findBy(columns);
        if(ObjectUtil.isEmpty(borrows)){
            return null;
        }
        return borrows.get(borrows.size() - 1);
    }
}
